import 'package:flutter/material.dart';
import 'package:yqys_target/utils/yq_colors.dart';

class FormListItem extends StatelessWidget {
  final double? paddingVertical;
  final bool required;
  final String? title;
  final Widget trailing;
  final bool showArrow;
  final VoidCallback? onTap;
  final bool? hideDivider;
  final Widget? leading;
  final Color? backgroundColor;
  const FormListItem({
    this.paddingVertical = 12,
    Key? key,
    this.required = true,
    this.title,
    required this.trailing,
    this.leading,
    this.showArrow = true,
    this.onTap,
    this.hideDivider = false,
    this.backgroundColor = Colors.white,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return InkWell(
      onTap: onTap,
      child: ColoredBox(
        color: backgroundColor ?? Colors.white,
        child: Column(
          children: [
            Padding(
              padding: EdgeInsets.symmetric(
                vertical: paddingVertical ?? 12,
                horizontal: 16,
              ),
              child: Row(
                children: [
                  // 必填星号
                  if (required)
                    const Text(
                      '*',
                      style: TextStyle(
                        color: Colors.red,
                        fontSize: 15,
                      ),
                    ),

                  // 标题
                  if (leading == null)
                    Text(
                      title ?? "",
                      style: TextStyle(
                        fontSize: 15,
                        fontWeight: FontWeight.bold,
                        color: YQColors.primary,
                      ),
                    ),
                  if (leading != null) leading!,
                  const Spacer(),
                  // 右侧内容
                  trailing,

                  // 箭头图标
                  if (showArrow)
                    const Padding(
                      padding: EdgeInsets.only(left: 8.0),
                      child: Icon(
                        Icons.chevron_right,
                        color: Colors.grey,
                        size: 20,
                      ),
                    ),
                ],
              ),
            ),

            // 分割线
            if (hideDivider == false)
              const Divider(
                color: Color.fromARGB(255, 239, 239, 239),
                height: 1,
                thickness: 0.5,
                indent: 16,
                endIndent: 16,
              ),
          ],
        ),
      ),
    );
  }
}
